package cn.kgc.shiro02.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author: mosin
 * @version: v1.0  2022/6/1
 *Applicaticontext 工具类 用户通过bean的名字获取实体类对象
 */
@Component
public class ApplicationContextUtil implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    //ApplicationContext 对象 在spring容器启动时 会自动注入
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            this.applicationContext = applicationContext;
    }

    public static Object getBean(String beanName){

        Object bean = applicationContext.getBean(beanName);
        return bean;
    }
}
